<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        canvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<canvas id="box" width="800" height="800"></canvas>
<script type="text/javascript">
    var box=document.getElementById("box");
    var pen=box.getContext("2d");
    pen.clearRect(0,0,box.width,box.height);//清除画布
    var ele=pen.createLinearGradient(200,200,500,500);
    ele.addColorStop(0,"red");
    ele.addColorStop(0.5,"green");
    ele.addColorStop(1,"blue");

    pen.beginPath();
    pen.moveTo(50,30);
    pen.lineTo(800,30);
    pen.strokeStyle=ele;
    pen.closePath();
    pen.stroke();

    pen.beginPath();
    pen.rect(0,300,500,100);
    pen.fillStyle=ele;
    pen.fill();
    pen.closePath();
    pen.stroke();

    var ra=pen.createRadialGradient(400,400,10,400,400,400);
    ra.addColorStop(0,"red");
    ra.addColorStop(0.5,"green");
    ra.addColorStop(1,"blue");

    pen.beginPath();
    pen.arc(400,400,100,0,Math.PI*2);
    pen.fillStyle=ra;
    pen.fill();
    pen.closePath();
    pen.stroke();
</script>,
</body>
</html>